#pragma once

#include "noncopyable.h"

#include <functional>
#include <thread>
#include <memory>
#include <unistd.h>
#include <string.h>
#include <atomic>

/**
 * @brief 封装Tread类
 *
 */
class Thread : noncopyable
{
public:
    using ThreadFunc = std::function<void()>;

    explicit Thread(ThreadFunc func, const std::string &name = "");
    ~Thread();

    void start();
    void join();

    bool started() const
    {
        return started_;
    }
    pid_t tid() const
    {
        return tid_;
    }
    const std::string &name() const
    {
        return name_;
    }

private:
    void setDefaultName();

    bool started_;
    bool joined_;
    std::shared_ptr<std::thread> thread_;
    pid_t tid_;
    ThreadFunc func_;
    std::string name_;
    static std::atomic_int numCreated_;
};